from models import BasicTextStyle


def convert_to_images(related_info, video_time):
    """
     处理额外 插图
    """
    print(related_info)
    print("-=============")
    images_clips = []
    for info in related_info:
        if info.type_in == 1:
            if float(info.start_time) > video_time:
                image_clip = {
                    "VideoTrackClips": [{}]
                }
                images_clips.append(image_clip)
                continue  # 使用continue而不是return，继续循环
            else:
                TimelineIn = float(info.start_time)
            # 结束前
        if info.type_in == 2:
            if float(info.end_time) < video_time:
                time = video_time - float(info.end_time)
                Duration = time - float(info.start_time)
                if Duration < 0:
                    image_clip = {
                        "VideoTrackClips": [{}]
                    }
                    images_clips.append(image_clip)
                    continue

            else:
                image_clip = {
                    "VideoTrackClips": [{}]
                }
                images_clips.append(image_clip)
                continue  # 使用continue而不是return，继续循环
            # 开始后
        if info.type_out == 1:
            if float(info.start_time) > video_time:
                image_clip = {
                    "VideoTrackClips": [{}]
                }
                images_clips.append(image_clip)
                continue  # 使用continue而不是return，继续循环
            else:
                TimelineIn = float(info.start_time)
            # 结束前
        if info.type_out == 2:
            if float(info.end_time) < video_time:
                time = video_time - float(info.end_time)
                Duration = time - float(info.start_time)
                if Duration < 0:
                    image_clip = {
                        "VideoTrackClips": [{}]
                    }
                    images_clips.append(image_clip)
                    continue

            else:
                image_clip = {
                    "VideoTrackClips": [{}]
                }
                images_clips.append(image_clip)
                continue  # 使用continue而不是return，继续循环
        image_clip = {
            "VideoTrackClips": [{
                "MediaURL": info.path,
                "TimelineIn": TimelineIn,
                "Duration": Duration,
                "X": info.x,
                'Y': info.y,
                "Type": "Image",
                "Width": info.width,
                "Height": info.height,
            }
            ]}

        images_clips.append(image_clip)
    return images_clips
